#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
using ll = long long;
int n, m, k, x;
ll qmi(ll a, ll k)
{
    ll res = 1;
    while (k)
    {
        if (k & 1) res = res * a % n;
        a = a * a % n;
        k >>= 1;
    }
    return res;
}
int main()
{
    cin >> n >> m >> k >> x;
    int pos = (qmi(10, k) * m) % n;
    cout << (pos + x) % n << endl;
}